#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=110;
int T;
int n;
int a[N],c[N];
int r1,r2,b1,b2,ans=0;
inline int read()
{
    int f=1,x=0;
    char ch=getchar();
    while(ch>'9'||ch<'0')
    {
        f=-f;ch=getchar();
    }
    while(ch<='9'&&ch>='0')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return f*x;
}
inline void write(int x)
{
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    T=read();
    while(T--)
    {
        n=read();
        for(int i=1;i<=n;i++) a[i]=read();
        for(int i=1;i<=n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                if(a[i]==a[j]) {c[j]=c[i]=1;ans+=a[j];i=j;break;}
            }
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                if(a[i]==a[j]&&c[j]!=1&&c[i]!=1) {c[j]=c[i]=2,ans+=a[j],i=j;break;}
            }
        }
        for(int i=1;i<=n;i++) c[i]=0;
        write(ans);ans=0;cout<<endl;
    }
    return 0;
}
